package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminController")
@Slf4j
@Api(tags = "分类管理")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/admin/category/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("分页查询");
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除员工分类
     * @param id
     * @return
     */
    @DeleteMapping("/admin/category")
    @ApiOperation("根据id删除员工分类")
    public Result deleteById(@PathVariable Long id){
        log.info("根据id删除员工分类");
        categoryService.deleteById(id);
        return Result.success();
    }

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping("/admin/category")
    @ApiOperation("新增分类")
    public Result<String> saveClassifcation(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增分类");
        categoryService.saveClassifcation(categoryDTO);
        return Result.success();
    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @PutMapping("/admin/category")
    @ApiOperation("修改分类")
    public Result<String>updateClassification(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类");
        categoryService.updateClassification(categoryDTO);
        return Result.success();
    }

    /**
     * 启动或禁用分类
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/admin/category/status/{status}")
    @ApiOperation("启动或禁用分类")
    public Result<String> startOrStop(@PathVariable Integer status,Long id){
        log.info("启动或禁用分类");
        categoryService.startOrStop(status,id);
        return Result.success();
    }

    /**
     * 浏览
     * @param type
     * @return
     */
    @GetMapping("/admin/category/list")
    @ApiOperation("浏览")
    public Result<List<Category>> seeClassificationByType(Integer type){
        List<Category> list=categoryService.seeClassificationByType(type);
        return Result.success(list);
    }

}
